//  this library.
import 'package:hktk_app/ienum/practice/ct_enum.dart';
import 'package:hktk_app/ienum/question/answer_type_enum.dart';
import 'package:hktk_app/ienum/question/collect_type_enum.dart';
import 'package:hktk_app/ienum/question/first_type_enum.dart';
import 'package:hktk_app/model/practice/practice_question_model.dart';
import 'package:hktk_app/util/my_util.dart';

/// 试题集合相关模型
class PaperDataModel {
  /// 集合名称
  String name;

  /// 集合id
  String id;

  /// 集合id(每日一练记录id/章节id/试卷id)
  String collectId;

  /// 初始显示页面下标
  int lastIndex;

  /// 对应的试题类型
  CtEnum rType;

  /// 对应的试题相关数据
  List<DtkInfoModel> dtkList;

  /// 大题型相关数据
  List<BogInfoModel> bogDtkList;

  /// 新增/减少 做题数量
  int dc;

  /// 新增/减少 错题数量
  int ec;

  /// 新增/减少 收藏试题数量
  int cc;

  /// 考试时长
  int examTime;

  /// 开始时间戳
  int startDate;

  PaperDataModel({
    required this.name,
    required this.id,
    required this.collectId,
    required this.lastIndex,
    required this.rType,
    required this.dtkList,
    required this.bogDtkList,
    this.dc = 0,
    this.ec = 0,
    this.cc = 0,
    this.examTime = 0,
    required this.startDate,
  });
}

class DtkInfoModel {
  /// 对应的下标
  int index;

  /// 试题对应的id
  String id;

  /// 试题类型
  FirstTypeEnum type;

  /// 试题签名
  String sign;

  /// 题干数据冗余
  List<Stem>? st;

  /// 用户答案
  List<String> userAns;

  /// 用户回答时间戳
  int? ansDate;

  /// 试题答案64编码
  String? answerBase64;

  /// 是否显示解析
  bool showJx;

  /// 试题答案状态
  AnswerTypeEnum ansType;

  /// 试题收藏状态
  CollectTypeEnum collType;

  /// 试题收藏时的时间戳
  int? collData;

  DtkInfoModel({
    required this.index,
    required this.id,
    required this.type,
    required this.sign,
    this.showJx = false,
    this.ansType = AnswerTypeEnum.notDone,
    this.collType = CollectTypeEnum.def,
    this.collData,
    this.st,
    required this.userAns,
    this.ansDate,
    this.answerBase64,
  });

  String getUserAnsStr() {
    if (userAns.isEmpty) {
      return "";
    }
    return MyUtil.getUserAnsStr(userAns, type);
  }
}

// 答题卡，本大题需要的数据
class BogInfoModel {
  /// 对应的大题名称
  String name;

  /// 试题类型
  FirstTypeEnum type;

  /// 试题总数
  int total;

  /// 对应试题信息
  List<DtkInfoModel> dtkList;

  BogInfoModel({
    required this.name,
    required this.type,
    required this.total,
    required this.dtkList,
  });
}
